<template>
  <a-spin :spinning="confirmLoading">
    <a-form :form="form">

      <a-row>

        <a-col :xs="24" :sm="12">
          <a-form-item label="合同编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input v-decorator="['contractNum', validatorRules.contractNum]" :disabled="disableSubmit"
                     placeholder="请输入合同编号"></a-input>
          </a-form-item>
        </a-col>
        <a-col :xs="24" :sm="12">
          <a-form-item label="合同类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-search-select-tag type="list" v-decorator="['type', validatorRules.type]"
                                 :trigger-change="true" dict="zcgl_contract_type" :disabled="disableSubmit"
                                 placeholder="请选择合同类型"/>
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol">

            <JSelectMultiCustomer
              placeholder="请选择客户名称" :disabled="disableSubmit" :trigger-change="true"
              v-decorator="['customerId', validatorRules.customerId]"></JSelectMultiCustomer>

          </a-form-item>
        </a-col>
        <a-col :xs="24" :sm="12">
          <a-form-item label="资产名称" :labelCol="labelCol" :wrapperCol="wrapperCol">

            <j-select-multi-asset
              placeholder="请选择资产信息"  :disabled="disableSubmit || formType == 1" :trigger-change="true"
              v-decorator="['assetId', validatorRules.assetId]" @change="assetChange"></j-select-multi-asset>

          </a-form-item>
        </a-col>
        <a-col :xs="24" :sm="12">
          <a-form-item label="资产明细" :labelCol="labelCol" :wrapperCol="wrapperCol">

            <j-multi-select-tag
              :trigger-change="true"
              v-decorator="['assetSubIds', validatorRules.assetSubIds]"
              :options="searchOptions"
              :disabled="disableSubmit || formType == 1"
              @change="assetSubChange"
              placeholder="请选择资产明细" />
            <!--              , validatorRules.assetSubIds-->
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="打印模版" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-search-select-tag type="list" v-decorator="['printTemplateId', validatorRules.printTemplateId]"
                                 :trigger-change="true" dict="sys_sms_template,template_name,id,template_code='houses_rental_contract'" :disabled="disableSubmit"
                                 placeholder="请选择打印模版"/>
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="计费方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-dict-select-tag type="radio" v-decorator="['chargeType', validatorRules.chargeType]"
                               :trigger-change="true" dictCode="zcgl_contract_charge_type" :disabled="disableSubmit"
                               placeholder="请选择计费方式"/>
          </a-form-item>
        </a-col>

        <!--          <a-col :xs="24" :sm="12">-->
        <!--            <a-form-item label="合同模版" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--              <j-search-select-tag type="list" v-decorator="['contractTemplate', validatorRules.contractTemplate]"-->
        <!--                                   :trigger-change="true" dict="sys_sms_template,template_name,id" :disabled="disableSubmit"-->
        <!--                                   placeholder="请选择合同模版"/>-->
        <!--            </a-form-item>-->
        <!--          </a-col>-->

        <a-col :xs="24" :sm="12">
          <a-form-item label="商户名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input v-decorator="['merchantName', validatorRules.merchantName]"
                     :disabled="disableSubmit" placeholder="请输入商户名称"
                     style="width: 100%" />
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="经营业态" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input v-decorator="['manageStatus', validatorRules.manageStatus]"
                     :disabled="disableSubmit" placeholder="请输入经营业态"
                     style="width: 100%" />
            <!--              <JSearchSelectTag type="list"-->
            <!--                                v-decorator="['manageStatus', validatorRules.manageStatus]"-->
            <!--                                :trigger-change="true"-->
            <!--                                dict="zcgl_manage_status"-->
            <!--                                :disabled="disableSubmit" placeholder="请选择经营业态"/>-->
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="出租方" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-company-select-tag :disabled="disableSubmit" placeholder="请选择出租方" v-decorator="[ 'rentCompanyId', validatorRules.rentCompanyId]" style="width: 100%" :trigger-change="true"/>
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="出租面积" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input-number v-decorator="['rentableArea', validatorRules.rentableArea]" @blur="calculation"
                            :disabled="disableSubmit" placeholder="请输入出租面积"
                            style="width: 100%" />
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="租金单价" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input-number v-decorator="['rentPrice', validatorRules.rentPrice]" @blur="calculation"
                            :disabled="disableSubmit" placeholder="请输入租金单价"
                            style="width: 100%" />
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="月租金" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input-number v-decorator="['monthlyRent', validatorRules.monthlyRent]" @blur="calculationCashDeposit"
                            :disabled="disableSubmit" placeholder="请输入月租金"
                            style="width: 100%" />
          </a-form-item>
        </a-col>
        <a-col :xs="24" :sm="12">
          <a-form-item label="保证金" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input-number v-decorator="['cashDeposit', validatorRules.cashDeposit]" :disabled="disableSubmit"
                            placeholder="请输入保证金" style="width: 100%" />
          </a-form-item>
        </a-col>
        <a-col :xs="24" :sm="12">
          <a-form-item label="违约金" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input-number v-decorator="['liquidatedDamages']" :disabled="disableSubmit"
                            placeholder="请输入违约金" style="width: 100%" />
          </a-form-item>
        </a-col>
        <a-col :xs="24" :sm="12">
          <a-form-item label="租金浮动比例" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input-number v-decorator="['contractChangeRatio', validatorRules.contractChangeRatio]"
                            :disabled="disableSubmit" placeholder="请输入合同租金浮动比例" style="width: 100%" />
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="支付方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-dict-select-tag type="list" v-decorator="['modeOfPayment', validatorRules.modeOfPayment]"
                               :trigger-change="true" dictCode="zcgl_lease_contract_paymenttype"
                               :disabled="disableSubmit" placeholder="请选择租金支付方式" />
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="合同期限" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input v-decorator="['contractPeriod', validatorRules.contractPeriod]" :disabled="disableSubmit"
                     placeholder="请输入合同期限"></a-input>
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="起租时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-date :disabled="disableSubmit" placeholder="请选择起租时间"
                    @change="rentStartTimeChange"
                    v-decorator="['rentStartTime', validatorRules.rentStartTime]"
                    :trigger-change="true" style="width: 100%" />
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="到租时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-date :disabled="disableSubmit" placeholder="请选择到租时间"
                    v-decorator="['rentEndTime', validatorRules.rentEndTime]"
                    :trigger-change="true" style="width: 100%" />
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="提前缴费天数" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input-number v-decorator="['beforeDay', validatorRules.beforeDay]"
                            :disabled="disableSubmit" placeholder="请输入提前缴费天数"
                            style="width: 100%" />
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="免租期限" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input v-decorator="['rentHolidayDay', validatorRules.rentHolidayDay]" :disabled="disableSubmit"
                     placeholder="请输入免租期限" @change="rentHolidayChange"></a-input>
          </a-form-item>
        </a-col>

        <!--          <a-col :xs="24" :sm="12">-->
        <!--            <a-form-item label="免租时间" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--              <a-select v-decorator="['rentHolidayDay', validatorRules.rentHolidayDay]" :options="rentHolidayDayOptions"-->
        <!--                        placeholder="请选择免租时间"-->
        <!--                        :disabled="disableSubmit"-->
        <!--                        @change="rentHolidayDayChange"></a-select>-->
        <!--            </a-form-item>-->
        <!--          </a-col>-->

        <a-col :xs="24" :sm="12">
          <a-form-item label="免租开始日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-date :disabled="disableSubmit" placeholder="请选择免租开始日期"
                    v-decorator="['rentHolidayStart']"
                    :trigger-change="true" @change="rentHolidayStartChange" style="width: 100%" />
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="免租结束日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-date :disabled="disableSubmit" placeholder="请选择免租结束日期"
                    v-decorator="['rentHolidayEnd', validatorRules.rentHolidayEnd]"
                    :trigger-change="true" @change="rentHolidayEndChange" style="width: 100%" />
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="签约日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-date :disabled="disableSubmit" placeholder="请选择签约日期"
                    v-decorator="['signingDate']"
                    :trigger-change="true" style="width: 100%" />
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12" v-is-group>
          <a-form-item label="所属公司（管理公司）" v-is-group :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-company-select-tag placeholder="请选择所属公司（管理公司）" :disabled="disableSubmit" v-decorator="[ 'companyId', validatorRules.companyId]" :trigger-change="true"/>
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-upload v-decorator="['accessory']" :disabled="disableSubmit" :trigger-change="true"></j-upload>
          </a-form-item>
        </a-col>

        <a-col :span="24">
          <a-form-item label="补充条款" :labelCol="labelCol2" :wrapperCol="wrapperCol2">
            <a-textarea v-decorator="['supplementaryTerms']" :disabled="disableSubmit" rows="3"
                        placeholder="请输入补充条款"></a-textarea>
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12" v-if="formType == 2">
          <a-form-item label="退回租金" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input-number v-decorator="['refundRent']" placeholder="请输入退回租金" :disabled="disableSubmit && disableFormType2"
                            style="width: 100%" />
          </a-form-item>
        </a-col>
        <a-col :xs="24" :sm="12" v-if="formType == 2" >
          <a-form-item label="退回保证金" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input-number v-decorator="['refundCashDeposit']" placeholder="请输入退回保证金"
                            :disabled="disableSubmit && disableFormType2"
                            style="width: 100%" />
          </a-form-item>
        </a-col>

<!--        <a-col :xs="24" :sm="12" v-if="formType == 3">-->
<!--          <a-form-item label="月租金" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--            <a-input-number v-decorator="['renewMonthlyRent', validatorRules.renewMonthlyRent]"-->
<!--                            :disabled="disableSubmit && disableFormType3" placeholder="请输入月租金"-->
<!--                            style="width: 100%" />-->
<!--          </a-form-item>-->
<!--        </a-col>-->

        <a-col :xs="24" :sm="12" v-if="formType == 3">
          <a-form-item label="到租时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-date :disabled="disableSubmit && disableFormType3" placeholder="请选择到租时间"
                    v-decorator="['endDate', validatorRules.endDate]"
                    :trigger-change="true" style="width: 100%" />
          </a-form-item>
        </a-col>

        <a-col v-if="formType == 0" :span="24">
          <a-form-item label="备注" :labelCol="labelCol2" :wrapperCol="wrapperCol2">
            <a-textarea rows="4" v-decorator="['remark']" placeholder="请输入备注"
                        :disabled="disableSubmit"
                        style="width: 100%" />
          </a-form-item>
        </a-col>

        <a-col v-else :span="24">
          <a-form-item label="备注" :labelCol="labelCol2" :wrapperCol="wrapperCol2">
            <a-textarea rows="4" v-decorator="['remark']" placeholder="请输入备注"
                        :disabled="disableFormType1 || disableFormType2 || disableFormType3"
                        style="width: 100%" />
          </a-form-item>
        </a-col>

      </a-row>
    </a-form>

    <!-- 子表单区域 -->

    <!-- 子表单区域  v-show="formType == 0 || formType == 1 || formType == 3"-->
    <a-tabs v-model="activeKey" @change="handleChangeTabs">
      <a-tab-pane tab="分段租金信息" :key="refKeys[0]" :forceRender="true">
        <j-editable-table  v-if="formType == 3"
          :ref="refKeys[0]"
          :loading="leaseContractStandardRentTable.loading"
          :columns="leaseContractStandardRentTable.columns"
          :dataSource="leaseContractStandardRentTable.dataSource"
          :maxHeight="300"
          :disabled="disableFormType3"
          :rowNumber="true"
          :rowSelection="!disableFormType3"
          :actionButton="!disableFormType3" />

        <j-editable-table  v-else
          :ref="refKeys[0]"
          :loading="leaseContractStandardRentTable.loading"
          :columns="leaseContractStandardRentTable.columns"
          :dataSource="leaseContractStandardRentTable.dataSource"
          :maxHeight="300"
          :disabled="disableSubmit"
          :rowNumber="true"
          :rowSelection="!disableSubmit"
          :actionButton="!disableSubmit" />
      </a-tab-pane>
    </a-tabs>

  </a-spin>
</template>

<script>

import { httpAction } from '@/api/manage'
import pick from 'lodash.pick'
import { dateAdd } from '@/utils/util'
import JDate from '@/components/jeecg/JDate'
import JUpload from '@/components/jeecg/JUpload'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JMultiSelectTag from '@/components/dict/JMultiSelectTag'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import JSelectMultiAsset from '@/components/jeecgbiz/JSelectMultiAsset'
import JSelectMultiCustomer from '@/components/jeecgbiz/JSelectMultiCustomer'
import { AssetSubMixin } from '@/api/assetSubMixin'
import { FormTypes, getRefPromise } from '@/utils/JEditableTableUtil'
import { queryAssetSubTotalAreaByIds, queryAssetTotalAreaByIds } from '@api/asset'
import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
import JCompanySelectTag from '@comp/jeecg/JCompanySelectTag'
import { IS_GROUP } from '@/store/mutation-types'

export default {
  name: 'LeaseContractInfoModal',
  mixins: [JEditableTableMixin, AssetSubMixin],
  components: {
    JDate,
    JUpload,
    JDictSelectTag,
    JMultiSelectTag,
    JSearchSelectTag,
    JSelectMultiCustomer,
    JCompanySelectTag,
    JSelectMultiAsset
  },
  data () {
    return {
      searchOptions: [],
      rentHolidayDayOptions: [
        { value: 0, label: '不免租' },
        { value: 1, label: '1个月' },
        { value: 2, label: '2个月' }
      ],
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 3 }
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 21 }
      },
      width: 1200,
      disableSubmit: false,
      disableFormType1: false,
      disableFormType2: false,
      disableFormType3: false,
      formType: -1,
      // 新增时子表默认添加几行空数据
      addDefaultRowNum: 0,
      assetTotalArea: 0,
      validatorRules: {
        contractNum: {
          rules: [
            { required: false, message: '请输入合同编号!' }
          ]
        },
        type: {
          rules: [
            { required: true, message: '请选择合同类型!' }
          ]
        },
        assetId: {
          rules: [
            { required: true, message: '请输入资产名称!' }
          ]
        },
        assetSubIds: {
          rules: [
            { required: false, message: '请输入资产明细!' }
            // { validator: this.validateCode }
          ]
        },
        chargeType: {
          rules: [
            { required: true, message: '请选择计费方式!' }
            // { validator: this.validateCode }
          ]
        },
        printTemplateId: {
          rules: [
            { required: true, message: '请选择打印模版!' }
            // { validator: this.validateCode }
          ]
        },
        // contractTemplate: {
        //   rules: [
        //     { required: true, message: '请选择合同打印模版!' }
        //     // { validator: this.validateCode }
        //   ]
        // },
        // assetSubIds: {
        //   rules: [
        //     // { required: true, message: '请输入资产明细!' }
        //     { validator: this.validateCode }
        //   ]
        // },
        customerId: {
          rules: [
            { required: true, message: '请输入客户名称!' }
          ]
        },
        rentCompanyId: {
          rules: [
            { required: true, message: '请选择出租方!' }
          ]
        },
        merchantName: {
          rules: [
            { required: false, message: '请输入商户名称!' }
          ]
        },
        rentableArea: {
          rules: [
            { required: true, message: '请输入出租面积!' },
            { pattern: /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/, message: '请输入零以上的数字' }
          ]
        },
        rentPrice: {
          rules: [
            { required: true, message: '请输入租金单价!' },
            { pattern: /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/, message: '请输入零以上的数字' }
          ]
        },
        monthlyRent: {
          rules: [
            { required: true, message: '请输入月租金!' },
            { pattern: /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/, message: '请输入零以上的数字' }
          ]
        },
        // renewMonthlyRent: {
        //   rules: [
        //     { required: false, message: '请输入续约月租金!' },
        //     { pattern: /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/, message: '请输入零以上的数字' }
        //   ]
        // },
        cashDeposit: {
          rules: [
            { required: false, message: '请输入保证金!' },
            { pattern: /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/, message: '请输入零或零以上的数字' }
          ]
        },
        contractChangeRatio: {
          rules: [
            { required: false, message: '请输入租金浮动比例!' },
            { pattern: /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/, message: '请输入零或零以上的数字' }
          ]
        },
        beforeDay: {
          rules: [
            { required: false, message: '请输入提前缴费天数!' },
            { pattern: /^([1-9]\d*|[0]{1,1})$/, message: '请输入零或零以上的整数' }
          ],
          initialValue: 20
        },
        rentHolidayDay: {
          rules: [
            { required: true, message: '请输入免租期限!' }
          ]
        },
        contractPeriod: {
          rules: [
            { required: true, message: '请输入合同期限!' }
          ]
        },
        rentStartTime: {
          rules: [
            { required: true, message: '请输入起租时间!' }
          ]
        },
        rentEndTime: {
          rules: [
            { required: false, message: '请输入到租时间!' }
          ]
        },
        modeOfPayment: {
          rules: [
            { required: true, message: '请输入租金支付方式!' }
          ]
        },
        rentHolidayEnd: {
          rules: [
            { required: false, message: '请选择免租结束日期!' }
          ]
        },
        endDate: {
          rules: [
            { required: false, message: '请选择续约到期日期!' }
          ]
        },
      },
      refKeys: ['leaseContractStandardRent'],
      tableKeys: ['leaseContractStandardRent'],
      activeKey: 'leaseContractStandardRent',
      // 合同分段租金信息表
      leaseContractStandardRentTable: {
        loading: false,
        dataSource: [],
        columns: [
          // {
          //   title: '合同信息',
          //   key: 'leaseContractId',
          //   type: FormTypes.sel_search,
          //   dictCode:"zcgl_lease_contract_info,contract_num,id",
          //   width:"200px",
          //   placeholder: '请输入${title}',
          //   defaultValue: '',
          //   validateRules: [{ required: true, message: '${title}不能为空' }],
          // },
          {
            title: '开始日期',
            key: 'startTime',
            type: FormTypes.date,
            // width:"200px",
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '结束日期',
            key: 'rentEndTime',
            type: FormTypes.date,
            // width:"200px",
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          // {
          //   title: '款项说明',
          //   key: 'paymentInstructions',
          //   type: FormTypes.sel_search,
          //   dictCode:"payment_instructions",
          //   // width:"200px",
          //   placeholder: '请输入${title}',
          //   defaultValue: '10',
          //   validateRules: [{ required: true, message: '${title}不能为空' }],
          // },
          {
            title: '月单价',
            key: 'monthlyPrice',
            type: FormTypes.inputNumber,
            // width:"200px",
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          }
        ]
      },
      url: {
        add: '/zcgl/leaseContractInfo/add',
        edit: '/zcgl/leaseContractInfo/edit',
        renewCheckModel: '/zcgl/leaseContractInfo/renewCheckModel',
        checkModel: '/zcgl/leaseContractInfo/checkModel',
        modifyCheckModel: '/zcgl/leaseContractInfo/modifyCheckModel',
        updateStatusCheck: '/zcgl/leaseContractInfo/updateStatusCheck',
        leaseContractStandardRent: {
          list: '/zcgl/leaseContractInfo/queryLeaseContractStandardRentByMainId'
        }
      }
    }
  },
  created () {

    // this.selectSub()
  },
  methods: {

    // validateCode (rule, value, callback) {
    //   if (this.searchOptions && this.searchOptions.length > 0) {
    //     if (value == null || value == undefined || value == '') {
    //       callback('请选择资产明细！')
    //       return
    //     }
    //   }
    //   callback()
    // },



    /***
     * 资产变更查询明细信息赋值给出租面积
     * @param assetId
     */
    assetChange (assetId) {
      let that = this
      if (assetId == this.model.assetId) return
      this.model.assetId = assetId
      this.selectSub(assetId/*, this.model.assetSubIds*/)
      if (assetId) {
        queryAssetTotalAreaByIds({
          ids: assetId
        }).then(res => {
          if (res.success) {
            if (res.result) {
              that.$nextTick(() => {
                that.assetTotalArea = res.result
                that.form.setFieldsValue({ rentableArea: res.result })
              })
            }
          }
        })

      }
    },

    /***
     * 资产明细变更查询明细信息赋值给出租面积
     * @param assetSubId
     */
    assetSubChange (assetSubId) {
      let that = this
      if (assetSubId) {
        queryAssetSubTotalAreaByIds({
          ids: assetSubId
        }).then(res => {
          if (res.success) {
            if (res.result) {
              that.$nextTick(() => {
                that.form.setFieldsValue({ rentableArea: that.assetTotalArea + res.result })
              })
            }
          }
        })
      }
    },

    //计算月租金和保证金
    calculation () {
      let rentPrice = this.form.getFieldValue('rentPrice')
      let rentableArea = this.form.getFieldValue('rentableArea')
      let monthlyRent = ''
      let cashDeposit = ''
      if (rentPrice != undefined && rentPrice != '' && rentableArea != undefined && rentableArea != '') {
        monthlyRent = (parseFloat(rentableArea) * parseFloat(rentPrice)).toFixed(2)
        cashDeposit = (parseFloat(monthlyRent) * 3).toFixed(2)
      }
      this.form.setFieldsValue({
        monthlyRent: monthlyRent,
        cashDeposit: cashDeposit
      })
    },

    //计算保证金
    calculationCashDeposit () {
      let monthlyRent = this.form.getFieldValue('monthlyRent')
      let cashDeposit = ''
      if (monthlyRent != undefined && monthlyRent != '') {
        cashDeposit = (parseFloat(monthlyRent) * 3).toFixed(2)
      }
      this.form.setFieldsValue({
        cashDeposit: cashDeposit
      })
    },
    //计算保证金
    rentStartTimeChange (rentStartTime) {
      let rentHolidayStart = this.form.getFieldValue('rentHolidayStart')
      if (rentHolidayStart){
        this.form.setFieldsValue({
          rentHolidayStart: rentStartTime,
        })
      }
      this.rentHolidayChangeB ()
    },
    //免租日期设置
    rentHolidayChange (e) {
      let rentHolidayDay = e.data
      let rentHolidayStart = this.form.getFieldValue('rentHolidayStart')
      let rentHolidayEnd = this.form.getFieldValue('rentHolidayEnd')
      this.rentHolidayChangeB(rentHolidayStart, rentHolidayEnd, rentHolidayDay)
    },
    //免租日期设置
    rentHolidayEndChange (rentHolidayEnd) {
      let rentHolidayDay = this.form.getFieldValue('rentHolidayDay')
      let rentHolidayStart = this.form.getFieldValue('rentHolidayStart')
      // let rentHolidayEnd = this.form.getFieldValue('rentHolidayEnd')
      this.rentHolidayChangeB(rentHolidayStart, rentHolidayEnd, rentHolidayDay)
    },
    //免租日期设置
    rentHolidayStartChange(rentHolidayStart) {
      let rentHolidayDay = this.form.getFieldValue('rentHolidayDay')
      // let rentHolidayStart = this.form.getFieldValue('rentHolidayStart')
      let rentHolidayEnd = this.form.getFieldValue('rentHolidayEnd')
      this.rentHolidayChangeB(rentHolidayStart, rentHolidayEnd, rentHolidayDay)
    },
    //免租日期设置
    rentHolidayChangeB (rentHolidayStart, rentHolidayEnd, rentHolidayDay) {
      if (rentHolidayStart || rentHolidayEnd || rentHolidayDay){
        this.validatorRules.rentHolidayDay.rules[0].required = true
        this.validatorRules.rentHolidayEnd.rules[0].required = true
      } else {
        this.validatorRules.rentHolidayDay.rules[0].required = false
        this.validatorRules.rentHolidayEnd.rules[0].required = false
      }
    },

    getAllTable () {
      let values = this.tableKeys.map(key => getRefPromise(this, key))
      return Promise.all(values)
    },

    showModal (r) {

      let isGroup = sessionStorage.getItem(IS_GROUP)
      if (isGroup == 1) {
        let companyName = {
          rules: [{
            required: true, message: '请选择所属公司!'
          }]
        }
        this.validatorRules.companyId = companyName
      }

      this.model = Object.assign({}, r)
      this.$nextTick(() => {
        if (this.model.leaseContractStandardRentList != undefined) {
          this.leaseContractStandardRentTable.dataSource = this.model.leaseContractStandardRentList
        } else if (this.formType != 3){
          this.selectSubD()
        }
        let keys = Object.keys(this.form.formItems)
        this.form.setFieldsValue(pick(this.model, keys))
        this.rentHolidayChangeB(this.model.rentHolidayStart, this.model.rentHolidayEnd, this.model.rentHolidayDay)
        this.selectSub1(this.model.assetId, this.model.assetSubIds)
        // this.form.setFieldsValue(fieldval)
      })
    },
    setProcessData (date, disableFormType) {
      if (date.routeName == "@/views/activiti/form/LeaseContractTakeEffect") {
        this.formType = 0
        this.disableSubmit = disableFormType
      } else if (date.routeName == "@/views/activiti/form/LeaseContractModify") {
        this.formType = 1
        this.disableSubmit = disableFormType
        // this.disableSubmit = true
        this.disableFormType1 = disableFormType
      } else if (date.routeName == "@/views/activiti/form/LeaseContractTermination") {
        this.formType = 2
        this.disableSubmit = true
        this.disableFormType2 = disableFormType
      } else if (date.routeName == "@/views/activiti/form/LeaseContractRenew") {
        // this.formType = 2
        // this.disableSubmit = true
        // this.disableFormType2 = disableFormType
        this.formType = 3
        this.disableSubmit = true
        this.disableFormType3 = disableFormType
        this.validatorRules.endDate.rules[0].required = true
        // this.validatorRules.renewMonthlyRent.rules[0].required = true
      }
    },
    selectSubD () {
      let params = { id: this.model.id }
      this.requestSubTableData(this.url.leaseContractStandardRent.list, params, this.leaseContractStandardRentTable)
    },
    /** 整理成formData */
    classifyIntoFormData (allValues) {
      let main = Object.assign(this.model, allValues.formValue)
      return {
        ...main, // 展开
        leaseContractStandardRentList: allValues.tablesValue[0].values
      }
    },
    validateError (msg) {
      this.$message.error(msg)
    },
    handleCancel () {
      this.close()
    },
    popupCallback (row) {
      let keys = Object.keys(this.form.formItems)
      this.form.setFieldsValue(pick(row, keys))
    }

  }
}
</script>